/*
 * @Author: funlee 
 * @Email: i@funlee.cn 
 * @Date: 2017-12-11 15:54:46 
 * @Last Modified time:   2017-12-11 15:54:46 
 * @Description: 交换地图
 *               呵呵------只能调换一次
 */
import ol from 'openlayers'
import 'openlayers/dist/ol.css'
import logo from '../../img/logo.png'

export default () => {
  // 创建第一个地图
  var map1 = new ol.Map({
    layers: [
      new ol.layer.Tile({
        source: new ol.source.OSM()
      })
    ],
    view: new ol.View({
      center: [13078573.75444912, 4800741.73727404],
      zoom: 8
    }),
    target: 'map1'
  });

  // 创建第二个地图
  var map2 = new ol.Map({
    layers: [
      new ol.layer.Tile({
        source: new ol.source.OSM()
      })
    ],
    view: new ol.View({
      center: [13078573.75444912, 4800741.73727404],
      zoom: 8
    }),
    target: 'map2'
  });

  document.querySelector('.exchange-btn').addEventListener('click', function () {
    // 改变两个地图的容器
    console.log('exchange')
    if (map1.getTarget() == 'map1') {
      map1.setTarget('map2')
      map2.setTarget('map1')
    } else {
      map1.setTarget('map1')
      map2.setTarget('map2')
    }    
  })
}